import request from '@/utils/request'

// 查询评论列表
export function listComment(query) {
  return request({
    url: '/getAllComments',
    method: 'get'
  })
}

// 查询评论详细信息
export function getComment(id) {
  return request({
    url: '/getComment/' + id,
    method: 'get'
  })
}

// 修改评论
export function updateComment(data) {
  return request({
    url: '/api/comments',
    method: 'put',
    data
  })
}

// 批量删除评论
export function batchDeleteComment(ids) {
  const idArray = ids.split(',');
  const promises = idArray.map(id => deleteComment(id));
  
  return Promise.all(promises).then(() => {
    return {
      code: 200,
      message: 'success',
      data: null
    }
  });
}

// 导出评论数据
export function exportComment(query) {
  return request({
    url: '/exportComments',
    method: 'get',
    params: query,
    responseType: 'blob'
  })
}

// 获取车辆的评论列表
export function getCarComments(carId) {
  return request({
    url: '/getCarComments/' + carId,
    method: 'get'
  })
}

// 获取用户的评论列表
export function getUserComments(userId) {
  return request({
    url: '/getUserComments/' + userId,
    method: 'get'
  })
}

// 获取评论的评分统计
export function getCommentStats(carId) {
  return request({
    url: '/getCommentStats/' + carId,
    method: 'get'
  })
}

// 获取所有评论
export function getAllComments() {
  return request({
    url: '/api/comments',
    method: 'get'
  })
}

// 根据车辆ID获取评论
export function getCommentsByCarId(carId) {
  return request({
    url: `/api/comments/car/${carId}`,
    method: 'get'
  })
}

// 根据用户ID获取评论
export function getCommentsByUserId(userId) {
  return request({
    url: `/api/comments/user/${userId}`,
    method: 'get'
  })
}

// 根据ID获取评论
export function getCommentById(commentId) {
  return request({
    url: `/api/comments/${commentId}`,
    method: 'get'
  })
}

// 添加评论
export function addComment(data) {
  return request({
    url: '/api/comments',
    method: 'post',
    data
  })
}

// 删除评论
export function deleteComment(commentId) {
  return request({
    url: `/api/comments/${commentId}`,
    method: 'delete'
  })
}

// 根据车辆ID删除所有评论
export function deleteCommentsByCarId(carId) {
  return request({
    url: `/api/comments/car/${carId}`,
    method: 'delete'
  })
}

// 根据用户ID删除所有评论
export function deleteCommentsByUserId(userId) {
  return request({
    url: `/api/comments/user/${userId}`,
    method: 'delete'
  })
}

// 条件查询评论
export function searchComments(data) {
  return request({
    url: '/api/comments/search',
    method: 'post',
    data
  })
} 